//
//  FunctionCardCell.m
//  QRMaster
//
//  Created by myApple on 16/5/11.
//  Copyright © 2016年 myApple. All rights reserved.
//

#import "FunctionCardCell.h"

@interface FunctionCardCell()
{
    UIImageView * cardImageView;
    UILabel * functionCardNameLabel;
    UILabel * communityNameLabel;
    UILabel * buildNameLabel;
}

@end

@implementation FunctionCardCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        [self prepareView];
    }
    return self;
}

-(void)prepareView
{
    float x = 16;
    float y = (56 - 38)/2.0;
    float width = 38;
    float height = 38;
    cardImageView = [[UIImageView alloc]initWithFrame:CGRectMake(x, y, width, height)];
    cardImageView.image = [UIImage imageNamed:@"ic_zcard"];
    [self.contentView addSubview:cardImageView];
    
    x = 72;
    y = 10;
    height = 20;
    width = UI_SCREEN_WIDTH - x - 16;
    functionCardNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(x, y,width, height)];
    functionCardNameLabel.font = [UIFont systemFontOfSize:16.0];
    [self.contentView addSubview:functionCardNameLabel];
    
    x = functionCardNameLabel.frame.origin.x;
    y += height;
    width = 100;
    height = 20;
    buildNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(x, y, width, height)];
    buildNameLabel.font = [UIFont systemFontOfSize:11.0];
    buildNameLabel.textColor = UIColorFromRGB(0x727272);
    [self.contentView addSubview:buildNameLabel];
    
    x += width;
    width = UI_SCREEN_WIDTH - x - 16;
    communityNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(x, y, width, height)];
    communityNameLabel.font = [UIFont systemFontOfSize:11.0];
    communityNameLabel.textColor = UIColorFromRGB(0x727272);
    [self.contentView addSubview:communityNameLabel];
    
}

-(void)setFunctionCardName:(NSString *)functionCardName
{
    _functionCardName = functionCardName;
    functionCardNameLabel.text = functionCardName;
}

-(void)setBuildingName:(NSString *)buildingName
{
    _buildingName = buildingName;
}

-(void)setFloorName:(NSString *)floorName
{
    _floorName = floorName;
}

-(void)setCommunityName:(NSString *)communityName
{
    _communityName = communityName;
    communityNameLabel.text = communityName;
}

-(void)setFunctionCardStatus:(NSInteger)functionCardStatus
{
    _functionCardStatus = functionCardStatus;
    switch (functionCardStatus) {
        case 1:
            buildNameLabel.text = @"";
            break;
        case 2:
            buildNameLabel.text = @"";
            break;
        case 3:
            buildNameLabel.text = _buildingName;
            break;
        default:
            break;
    }
    [self autoAdjuestFrameWithString:buildNameLabel.text];
}


#pragma mark ------------调整楼栋和集群的名称的现实大小
-(void)autoAdjuestFrameWithString:(NSString *)buildNameString
{
    NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:11.0],};
    CGSize textSize = [buildNameString boundingRectWithSize:CGSizeMake(200, 20) options:NSStringDrawingTruncatesLastVisibleLine attributes:attributes context:nil].size;
    float width = textSize.width;
    buildNameLabel.frame = CGRectMake(buildNameLabel.frame.origin.x, buildNameLabel.frame.origin.y, width, buildNameLabel.frame.size.height);
    if (width == 0) {
        communityNameLabel.frame = CGRectMake(buildNameLabel.frame.origin.x + width, communityNameLabel.frame.origin.y, UI_SCREEN_WIDTH - width - buildNameLabel.frame.origin.x, communityNameLabel.frame.size.height);
    }
    else
    {
        communityNameLabel.frame = CGRectMake(buildNameLabel.frame.origin.x + width + 12, communityNameLabel.frame.origin.y, UI_SCREEN_WIDTH - width - 12 -buildNameLabel.frame.origin.x, communityNameLabel.frame.size.height);
    }
    
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
